<?php
use Entities\Contatos;

include_once '../templates/topo.php';

$id= '';

if(isset($_REQUEST['id']))
$id = $_REQUEST['id'];

$contato = $em->find("Entities\Contatos", $id);
if(empty($contato))
$contato = new Contatos();
?>
<script>
		contato = new Contatos();
	</script>
<div class="tabs center">
<ul>
	<li><a href="#tabs-1">Contatos</a></li>
</ul>
<div id="tabs-1">
	<div cols='4'>


		<div class='field'>
			<label>Nome</label> 
			<input type="hidden" value='<?php echo $id;?>' id='hidId' /> 
			<input type='text' id='txtNome'	value='<?php $contato->getFuncionario()->getNome();?>' size='50' />
		</div>

		<div class='field' style='margin-left:-2em'>
			<label>&nbsp;</label>
			<button id="btn_Abrir_Pesquisa">Abrir janela de busca de funcionarios</button>
			<script type="text/javascript">
				$("#btn_Abrir_Pesquisa").button({
					icons:{
						primary: "ui-icon-search"	
					},
					text:false
				 });

				$("#btn_Abrir_Pesquisa").click(function(){
					$("#popupBuscaCliente").dialog("open")
				});		
			</script>
		</div>
		
		<div class='field'><label>Email</label> <input type='text' id='txtEmail'
			size='50' value='<?php echo $contato->getEmail();?>' size='30' /></div>
		
		<div class='field'><label>Telefone</label> <input type='text'
			id='txtTelefone' value='<?php echo $contato->getTelefone();?>'
			size='30' /></div>
		
		<div class='field'><label>Celular</label> <input type='text'
			id='txtCelular' value='<?php echo $contato->getCelular();?>' size='30' />
		</div>
		
		<div class='field'><label>Nextel</label> <input type='text'
			id='txtNextel' value='<?php echo $contato->getNextel();?>' size='30' />
		</div>
		
		<div class='field'><label>Obra</label> <input type='text' id='txtObra'
			value='<?php echo $contato->getObra();?>' size='30' /></div>

</div>
</div>
<div class='footer'>
<button id='btnSalvar'>Salvar</button>
<button id='btnCancelar'>Cancelar</button>
<script type="text/javascript">
					$("#btnSalvar").click(function(){
						utils.ajax('contatos/salvar', {
							id: $("#hidId").val(),
							nome: $('#txtNome').val(),
							email: $('#txtEmail').val(),
							telefone: $('#txtTelefone').val(),
							celular: $('#txtCelular').val(),
							nextel: $('#txtNextel').val(),
							obra: $('#txtObra').val()
								
						}, function(xml){
								erro = $(xml).find('erro').text();
								if(parseInt(erro) == 0){
									msg = "O contato foi salvo com sucesso!";

									$('#txtNome').val(''),
									$('#txtEmail').val(''),
									$('#txtTelefone').val(''),
									$('#txtCelular').val(''),
									$('#txtNextel').val(''),
									$('#txtObra').val('')
								}
								else{
									msg = "O contato NAO foi salvo com sucesso!";
								}
								alert(msg, 'Contato');
						});
					});
				</script></div>
</div>

<div id="popupBuscaCliente">
<div class="search_field_group"><label>Buscar</label> <input type='text'
	id='txtBusca' value='' size='30' />

<button id="btnBuscarCliente">Buscar Funcionario</button>

<script type="text/javascript">
				$("#btnBuscarCliente").button({
					icons:{
						primary: "ui-icon-search"	
					},
					text:false
					})
			</script></div>
</div>

<script type="text/javascript">
		$("#popupBuscaCliente").dialog({
			modal:true,
			width:500,
			height:400, 
			title:"Clientes", 
			autoOpen:false
			})
			
<!--

//-->
</script>
>



<?php
if(!$popup)
include_once '../templates/footer.php';
?>